//
//  EeVideoPlayer.swift
//  soapp_Example
//
//  Created by zhuxietong on 2019/4/27.
//  Copyright © 2019 CocoaPods. All rights reserved.
//

import Foundation
import UIKit
import AVFoundation
import AVKit
import Eelay

class EeVideoPlayer:TypeInitController{
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        let session = AVAudioSession.sharedInstance()
        do{
           try session.setCategory(.playback)
        }catch{
            
        }
        self.title = "视频播放".loc
        self.top_style = EeTopStyle.blur_dark
        EeAudioPlayer.shared.stopAction()

        let urlString = mo.model["url",""]
//        print("-----_SS|\(urlString)")

        var url:URL? = nil
        if urlString.hasPrefix("http")
        {
            url = URL(string: urlString)
        }else{
            url = URL(fileURLWithPath: urlString)
        }
        guard let _url = url else {
            return
        }
        
        
        let player = AVPlayer(url: _url)
        let ctr = AVPlayerViewController()
        ctr.player = player
        ctr.videoGravity = .resizeAspect
        ctr.allowsPictureInPicturePlayback = true
        ctr.showsPlaybackControls = true
        self.addChild(ctr)
        
        guard let v = ctr.view else{return}
        jo_contentView.eelay = [
            [v,[ee.T.L.B.R]]
        ]
        player.play()
        
//        [session setCategory:AVAudioSessionCategoryPlayback error:nil];
    }
}
